<?php

use think\migration\Seeder;

class AirQualityWeatherForecastDayData extends Seeder
{

    public function run()
    {
        $table = $this->table('air_quality_weather_forecast_day');

        $rows = [];
        $num  = 7;
        $i    = 0;
        while ($num > 0) {
            //step1:风向
            $typeArr    = ['东风', '西风', '南风', '北风'];
            $randomKeys = array_rand($typeArr);

            //step2:总云量对应的天气名称及图标
            $cloudCover       = mt_rand(0, 100);
            $skyCondition     = '';
            $skyConditionIcon = '';
            if ($cloudCover >= 0 && $cloudCover < 30) {
                $skyCondition     = '晴';
                $skyConditionIcon = 'icon-qing';
            }
            if ($cloudCover >= 30 && $cloudCover < 60) {
                $skyCondition     = '少云';
                $skyConditionIcon = 'icon-tianqi2';
            }
            if ($cloudCover >= 60 && $cloudCover < 90) {
                $skyCondition     = '多云';
                $skyConditionIcon = 'icon-tianqizitiku02';
            }
            if ($cloudCover >= 90 && $cloudCover <= 100) {
                $skyCondition     = '阴';
                $skyConditionIcon = 'icon-yintian';
            }

            //step3:插入的数组
            $rows[] = [
                //step1:地区
                'region_id'                  => 53,

                //step2:时间
                'predict_time'               => date('Y-m-d', time() + 3600 * $i) . ':00:00',   //预报时间-7天168小时
                'publish_time'               => date('Y-m-d H', time()) . ':00:00',                         //发布时间-7天168小时
                'create_time'                => date('Y-m-d H:i:s', time()), //插入时间
                //step3:天气六参数（作为天气汇总的参数，与按小时的不一样）
                //气温
                'maximum_temperature'        => mt_rand(-20, 20),
                'minimum_temperature'        => mt_rand(-20, 20),
                'average_temperature'        => mt_rand(-20, 20),
                //风力
                'highest_wind'               => mt_rand(-20, 20),
                'minimum_wind'               => mt_rand(-20, 20),
                'average_wind'               => mt_rand(-20, 20),
                //风向（注：这里标识，风向最多的次数）
                'wind_direction'             => $typeArr[$randomKeys],
                //湿度
                'maximum_humidity'           => mt_rand(1, 12),
                'minimum_humidity'           => mt_rand(1, 12),
                'average_humidity'           => mt_rand(1, 12),
                //最大云量
                'maximum_cloud_cover'        => $cloudCover,
                'maximum_sky_condition'      => $skyCondition,
                'maximum_sky_condition_icon' => $skyConditionIcon,
                //最小云量
                'minimum_cloud_cover'        => $cloudCover,
                'minimum_sky_condition'      => $skyCondition,
                'minimum_sky_condition_icon' => $skyConditionIcon,
                //平均云量
                'average_cloud_cover'        => $cloudCover,
                'average_sky_condition'      => $skyCondition,
                'average_sky_condition_icon' => $skyConditionIcon,
                //气压
                'maximum_pressure'           => mt_rand(500, 1000),
                'minimum_pressure'           => mt_rand(500, 1000),
                'average_pressure'           => mt_rand(500, 1000),
            ];
            $num--;
            $i++;
        }

        $table->insert($rows)->save();
    }
}
